package cn.iot.controller.sys;

import cn.iot.common.dto.ResultMsg;
import cn.iot.sys.entity.SysDevice;
import cn.iot.sys.service.SysDeviceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/sys/device")
public class SysDeviceController {
    @Autowired
    private SysDeviceService sysDeviceService;
    private Logger logger = LoggerFactory.getLogger(getClass());

    @PostMapping("add")
    public ResultMsg addDevice(@RequestBody SysDevice sysDevice){
        logger.info("SysDeviceController add sysDevice{}",sysDevice);
        ResultMsg msg = sysDeviceService.addSysDevice(sysDevice);
        logger.debug("SysDeviceController add msg{}",msg);
        return msg;
    }
    @PostMapping("getSysDeviceList")
    public ResultMsg getSysDeviceList(@RequestParam Map<String,Object> map){
        logger.info("SysDeviceController getSysDeviceList map{}",map);
        ResultMsg msg = sysDeviceService.getSysDeviceList(map);
        logger.debug("SysDeviceController getSysDeviceList msg{}",msg);
        return msg;
    }
    @PostMapping("upd")
    public ResultMsg updDevice(@RequestBody SysDevice sysDevice){
        logger.info("SysDeviceController updDevice sysDevice{}",sysDevice);
        ResultMsg msg = sysDeviceService.updSysDevice(sysDevice);
        logger.debug("SysDeviceController updDevice msg{}",msg);
        return msg;
    }
    @PostMapping("delSysDeviceById")
    public ResultMsg delSysDeviceById(@RequestParam int id){
        logger.info("SysDeviceController delSysDeviceById id{}",id);
        ResultMsg msg = sysDeviceService.delSysDeviceById(id);
        logger.debug("SysDeviceController delSysDeviceById msg{}",msg);
        return msg;
    }

    /**
     * 刷新设备状态
     * @param id
     * @return
     */
    @PostMapping("refresh")
    public ResultMsg refreshOnlineStatus(@RequestParam String id){
        logger.info("SysDeviceController refreshOnlineStatus id{}",id);
        ResultMsg msg = sysDeviceService.refreshOnlineStatus(id);
        logger.debug("SysDeviceController refreshOnlineStatus msg{}",msg);
        return msg;
    }
}
